#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 20 00:07:16 2021

@author: liqingsimac
"""

'''
#############################################
##EXample 3-1-1
import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(0,1,11)
y=x**2

fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x,y,'b-')
ax.vlines(x=1,ymin=-2,ymax=2)
ax.vlines(x=0,ymin=-2,ymax=2)
ax.hlines(y=0,xmin=-0.5,xmax=1.5)

ax.annotate('$y=2x$',(0.75,-0.5))
ax.annotate('$y=2x-4y/x$',(0.75,0.3))
ax.annotate('$y=-2x$',(0.75,1.3))
ax.annotate('0',(0.05,-0.2))
ax.annotate('1',(1.05,-0.2))
ax.annotate('x',(1.45,-0.2))
ax.annotate('y',(0.05,1.8))

fig.savefig('ode-example-3-1-1.png')
#############################################
'''


'''
#############################################
##EXample 3-1-2
import numpy as np
import matplotlib.pyplot as plt

a=0; b=2; N=7
x=np.linspace(a,b,N)

x1=np.linspace(a,b,N*10)
y1=-2-x1+2*np.exp(x1)

dx=(b-a)/(N-1)
y=np.zeros_like(x)

fig=plt.figure()
ax=fig.add_subplot(111)
for k in range(N-1):
    slope=x[k]+y[k]+1
    y[k+1]=y[k]+slope*dx
ax.plot(x,y,'bo-',label='Euler method')
ax.plot(x1,y1,'r-',label='Analytic solution')
ax.legend(loc='best')
fig.savefig('ode-example-3-1-2.png')
#############################################
'''

'''
#############################################
##EXample 3-2-2
import numpy as np
import matplotlib.pyplot as plt

#a=1/2 #区间端点
#a=2 
a=1
M=10 # 函数个数
N=21 # 区间中的分点个数
x=np.linspace(-a,a,N)
y=np.zeros([M,N])
for k in range(M):
    for m in range(N):
        y[k,]=(-1)**k+x**k
    plt.plot(x,y[k,],'-')
#fig.savefig('ode-example-3-2-2.png')
#############################################
'''


'''
#############################################
## EXample 3-3-2
import numpy as np
import matplotlib.pyplot as plt

a=5; b=5; N=21; M=21
stk=0.2 # length of each stick (line element)

x=np.linspace(-a,a,num=N)
y=np.linspace(-b,b,num=M)

fig=plt.figure()
ax=fig.add_subplot(111)
for k in range(N):
    for m in range(M):
        xp=x[k]
        yp=y[m]
        slope=(xp-yp)*np.exp(xp*yp*yp)
        dx=stk/np.sqrt(1+slope**2)
        dy=dx*slope
        ax.plot([xp-dx/2,xp+dx/2],[yp-dy/2,yp+dy/2],color='b')

#ax.set_aspect('equal')
fig.savefig('ode-example-3-3-2.png')
#############################################
'''

#'''
#############################################
## EXample 3-4-1
import numpy as np
import matplotlib.pyplot as plt

a=10; b=2; N=31; M=23
stk=0.2 # length of each stick (line element)

x=np.linspace(-a,a,num=N)
y=np.linspace(-b,b,num=M)

fig=plt.figure()
ax=fig.add_subplot(111)
for k in range(N):
    for m in range(M):
        xp=x[k]
        yp=y[m]
        slope=np.sin(xp*yp)
        dx=stk/np.sqrt(1+slope**2)
        dy=dx*slope
        ax.plot([xp-dx/2,xp+dx/2],[yp-dy/2,yp+dy/2],color='b')

#ax.set_aspect('equal')
fig.savefig('ode-example-3-4-1.png')
#############################################
#'''

'''
#############################################
## EXample 3-4-1
import numpy as np
import matplotlib.pyplot as plt

a=2; b=2; N=13; M=13
stk=0.2 # length of each stick (line element)

x=np.linspace(-a,a,num=N)
y=np.linspace(-b,b,num=M)

fig=plt.figure()
ax=fig.add_subplot(111)
for k in range(N):
    for m in range(M):
        xp=x[k]
        yp=y[m]
        slope=xp**2+(yp+1)**2
        dx=stk/np.sqrt(1+slope**2)
        dy=dx*slope
        ax.plot([xp-dx/2,xp+dx/2],[yp-dy/2,yp+dy/2],color='b')

ax.set_aspect('equal')
fig.savefig('ode-example-3-4-2.png')
#############################################
'''

